using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

using Material.Object;
using Material.Entity;


namespace Material.App
{
    public partial class FrmFindBarangDTL : Form
    {
        //private TblTransPemBarangDTL tblTransPemBarangDTL;
        //private TblTransPemBarangDTLEntity tblTransPemBarangDTLEntity;
        private string connStr = ConfigurationManager.ConnectionStrings["dbconnection"].ToString();
        public string idBarang = string.Empty;

        public FrmFindBarangDTL()
        {
            InitializeComponent();
            BindGrid();
            cbListParameter.SelectedIndex = 0;

            dataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque;
            dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
            dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;

            dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Green;
            dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Yellow;

            //dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            //dataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //dataGridView1.AllowUserToResizeColumns = false;
        }

        private void FrmFindBarang_Load(object sender, EventArgs e)
        {

        }

        private void BindGrid()
        {
            //tblTransPemBarangDTLEntity = new TblTransPemBarangDTLEntity(connStr);
            //dataGridView1.AutoGenerateColumns = false;
            //dataGridView1.DataSource = tblTransPemBarangDTLEntity.GetDataAll();
        }

        private void BindGridByNamaBarang()
        {
            //tblTransPemBarangDTL = new TblTransPemBarangDTL();
            //tblTransPemBarangDTL.NamaBarang = txtFind.Text;// Convert.ToInt32(cbListFind.SelectedValue);
            //tblTransPemBarangDTLEntity = new TblTransPemBarangDTLEntity(connStr);
            //dataGridView1.AutoGenerateColumns = false;
            //dataGridView1.DataSource = tblTransPemBarangDTLEntity.GetDataByNamaBarang(tblTransPemBarangDTL);
        }

        private void BindGridByKelompok()
        {
            //tblTransPemBarangDTL = new TblTransPemBarangDTL();
            //tblTransPemBarangDTL.IdKelompok = Convert.ToInt32(cbListFind.SelectedValue);
            //tblTransPemBarangDTLEntity = new TblTransPemBarangDTLEntity(connStr);
            //dataGridView1.AutoGenerateColumns = false;
            //dataGridView1.DataSource = tblTransPemBarangDTLEntity.GetDataByIdKelompok(tblTransPemBarangDTL);
        }

        private void BindGridBySatuan()
        {
            //tblTransPemBarangDTL = new TblTransPemBarangDTL();
            //tblTransPemBarangDTL.IdSatuan = Convert.ToInt32(cbListFind.SelectedValue);
            //tblTransPemBarangDTLEntity = new TblTransPemBarangDTLEntity(connStr);
            //dataGridView1.AutoGenerateColumns = false;
            //dataGridView1.DataSource = tblTransPemBarangDTLEntity.GetDataByIdSatuan(tblTransPemBarangDTL);
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.RowIndex > -1) && (e.ColumnIndex > -1))
            {

                switch (e.ColumnIndex)
                {
                    case 1:
                        //MessageBox.Show(Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()););
                        idBarang = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                        this.Close();
                        break;

                    case 6:
                       
                        break;
                }

            }
        }

        private void cbListParameter_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbListParameter.SelectedIndex == 0)
            {
                txtFind.Visible = false;
                btnFind.Visible = false;
                cbListFind.Visible = false;

                BindGrid();
            }
            else if (cbListParameter.SelectedIndex == 1)
            {
                //cbListFind.Visible = true;
                txtFind.Visible = true;
                btnFind.Visible = true;
                txtFind.Focus();
            }
            else if (cbListParameter.SelectedIndex == 2)
            {
                cbListFind.Visible = true;
                txtFind.Visible = false;
                btnFind.Visible = true;

                


                TblKelompokEntity tblKelompokEntity = new TblKelompokEntity(connStr);
                cbListFind.DataSource = tblKelompokEntity.GetDataAll();
                cbListFind.ValueMember = "Id";
                cbListFind.DisplayMember = "Kelompok";
            }
            else if (cbListParameter.SelectedIndex == 3)
            {
                cbListFind.Visible = true;
                txtFind.Visible = false;
                btnFind.Visible = true;

                TblSatuanEntity tblSatuanEntity = new TblSatuanEntity(connStr);
                cbListFind.DataSource = tblSatuanEntity.GetDataAll();
                cbListFind.ValueMember = "Id";
                cbListFind.DisplayMember = "Satuan";

            }
            
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            if (cbListParameter.SelectedIndex == 1)
            {
                if (txtFind.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Harus diisi");
                    return;
                }
                else
                {
                    BindGridByNamaBarang();
                }
            }

            if (cbListParameter.SelectedIndex == 2)
                BindGridByKelompok();

            if (cbListParameter.SelectedIndex == 3)
                BindGridBySatuan();

            if (cbListParameter.SelectedIndex ==0)
                BindGrid();



        }


    }
}